package com.primaryAlgorithm;

/**
 * Description:  没做完 以后再说
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-09-25 20:37:42
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-09-25     张李鑫                     1.0         1.0 Version
 */
public class Rotate {
    /**
     * <p>
     * 给定一个数组，将数组中的元素向右移动 k 个位置，其中 k 是非负数。
     * </p>
     *
     * @param arr
     * @return void
     * @Author zlx
     * @date 2021/9/25
     */
    public static void rotate(int[] arr, int k) {
        if (k == 0) {
            return;
        }
        int right = arr.length - k;
        int left = 0;
        while (right < arr.length && left < right) {
            swap(arr, left++, right++);
        }
        if (right == arr.length && left == k && 2 * k >= arr.length) {
            return;
        }
        while (right < arr.length) {
            int index = right;
            while (index > left) {
                swap(arr, index--, index);
            }
            right++;

        }

        while (left <= k) {
            int index = left;
            while (index < arr.length - 1) {
                swap(arr, index++, index);
            }
            left++;

        }
    }


    public static void swap(int[] arr, int j, int i) {
        int swap = arr[j];
        arr[j] = arr[i];
        arr[i] = swap;
    }

    public static void main(String[] args) {
        int[] nums = {1, 2, 3, 4, 5, 6, 7};
        rotate(nums, 3);
        System.out.println(123);
    }
}